﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using PRET.ReportDataDefine.UIData;
using PRET.ReportControlLib.ServiceReference;

namespace PRET.ReportControlLib.ReportView
{
    public partial class ProductiveTaskReportView : UserControl
    {
        private PRETWebServiceClient adapter = null;

        public ProductiveTaskReportView()
        {
            InitializeComponent();
            adapter = new PRETWebServiceClient();
        }

        //public void ShowReportView()
        //{
        //    if (this.adapter == null)
        //    {
        //        MessageBox.Show("ProductiveTaskReportView 没有初始化Server Adapter!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //        return;
        //    }

        //    this.productiveTaskReportViewer.LocalReport.DataSources.Clear(); //clear report
        //    // 从后台获所有生产线上的在产和待产的数据列表
        //    ProductiveTaskReport[] list = this.adapter.GetProductiveTaskReport();
        //    if (list != null && list.Length > 0)
        //    {
        //        Microsoft.Reporting.WinForms.ReportDataSource dataset = new Microsoft.Reporting.WinForms.ReportDataSource("ProductiveTaskReportDS"); // set the datasource
        //        this.productiveTaskReportViewer.LocalReport.DataSources.Add(dataset);
        //        dataset.Value = list.ToList<ProductiveTaskReport>();
        //    }
        //    this.productiveTaskReportViewer.LocalReport.Refresh();
        //    this.productiveTaskReportViewer.RefreshReport();
        //}

        private void reportViewBtn_Click(object sender, EventArgs e)
        {
            try
            {
                this.reportViewBtn.Enabled = false;

                if (this.adapter == null)
                {
                    MessageBox.Show("ProductiveTaskReportView 没有初始化Server Adapter!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                this.productiveTaskReportViewer.LocalReport.DataSources.Clear(); //clear report
                // 从后台获所有生产线上的在产和待产的数据列表
                ProductiveTaskReportTV[] list = this.adapter.GetProductiveTaskReport();
                if (list != null && list.Length > 0)
                {
                    Microsoft.Reporting.WinForms.ReportDataSource dataset = new Microsoft.Reporting.WinForms.ReportDataSource("ProductiveTaskReportTVDS"); // set the datasource
                    this.productiveTaskReportViewer.LocalReport.DataSources.Add(dataset);
                    dataset.Value = list.ToList<ProductiveTaskReportTV>();
                }
                this.productiveTaskReportViewer.LocalReport.Refresh();
                this.productiveTaskReportViewer.RefreshReport();
            }
            catch (Exception ex)
            {
                string msg = string.Format("ProductiveTaskReportView.reportViewBtn_Click() Failed: {0}.\r\nDetail: {1}", ex.Message, ex.StackTrace);
                MessageBox.Show(msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            { this.reportViewBtn.Enabled = true; }
        }
    }
}
